
import { queryRecordManagerList } from "../../../../service/manager_service"
let app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    themeStyle: "",

    switchArr: [
      {
        title: "待报备",
        key: "",
      },
      {
        title: "待审核",
        key: 1
      },
      {
        title: "审核成功",
        key: 2
      },
      {
        title: "审核失败",
        key: 3
      }

    ],
    recordList: [

    ],
    scrollRefreshStatus: true,
    isShowLoading: false,
    isBottomShow: false,
    page: 0,
    pageSize: 10,
    exStatus: 0,//0,1,2,3 审核状态
    status: 2,
    searchWord: "",
    //章的图标:
    wdfIcon: "https://saas.img.ylyc.top/icon/zhangwdfff_icon.png",//未到访
    wrgIcon: "https://saas.img.ylyc.top/icon/zhangwrggg_icon.png",//未认购
    wqyIcon: "https://saas.img.ylyc.top/icon/zhangwqyyy_icon.png",//未签约
    ydfIcon: "https://saas.img.ylyc.top/icon/zhangydff_icon.png",//已到访
    yrgIcon: "https://saas.img.ylyc.top/icon/zhangyrgg_icon.png",//已认购
    yqyIcon: "https://saas.img.ylyc.top/icon/zhangyqyy_icon.png",//已签约
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    if (app.globalData.themeStyle) {
      this.setData({
        themeStyle: app.globalData.themeStyle
      })
    }
    this.queryRecordManagerList();
  },


  //顶部切换
  switchAction(e) {
    let index = e.currentTarget.dataset.index;
    this.setData({
      exStatus: index,
      page: 0,
      recordList: [],
      isBottomShow: false
    })
    if (index == 0) {
      this.setData({
        status: 2
      })
    } else {
      this.setData({
        status: ""
      })
    }
    this.queryRecordManagerList();
  },
  //搜索返回
  searchAction(e) {
    this.setData({
      searchWord: e.detail.searchWord,
      page: 0,
      isBottomShow: false,
    })
    this.queryRecordManagerList();

  },


  //查询列表:
  queryRecordManagerList() {
    wx.showLoading();
    let pageNum = this.data.page;
    let pageSize = this.data.pageSize;
    queryRecordManagerList(this.data.page, this.data.pageSize, this.data.exStatus, this.data.searchWord).then(res => {
      wx.hideLoading();
      this.setData({
        scrollRefreshStatus: false,
      })
      console.log("JJLog:报备列表是:" + JSON.stringify(res));
      if (res.code == 200) {
        let tempArr = [];
        tempArr = this.data.recordList;
        if (tempArr.length > 0 && pageNum > 0) {
          //加载下一页:
          tempArr = tempArr.concat(res.data);
          if (res.data.length < pageSize) {
            this.setData({
              isShowLoading: false,
              isBottomShow: true,
            })
            this.setData({
              recordList: tempArr
            })
          } else if (res.data.length == pageSize) {
            this.setData({
              isShowLoading: false,
            })
            this.setData({
              recordList: tempArr
            })
          }
        } else {
          this.setData({
            isShowLoading: false,
          })
          this.setData({
            recordList: res.data
          })
          if (res.data.length < pageSize) {
            this.setData({
              isBottomShow: true
            })
          }
        }
      }
    }).catch(err => {
      console.error("JJLog:queryRecordManagerList:", err);
      wx.hideLoading();
      this.setData({
        scrollRefreshStatus: false,
      })
      let page = this.data.page;
      if (page > 0) {
        page = page - 1;
      }
      this.setData({
        isShowLoading: false,
        page: page
      })
      wx.showToast({
        title: err || "查询失败",
        icon: "none"
      })
    })
  },

  //去详情页面;
  pushToDetail(e) {
    let item = e.currentTarget.dataset.item;
    //无效报备
    if (item.status == -1 && item.examineStatus == 3) {
      return;
    }
    if (item.examineStatus == 0) {
      wx.navigateTo({
        url: '/firstPackage/pages/reportModule/checkRecordFirst/checkRecordFirst?id=' + item.id,
      })
    } else {
      wx.navigateTo({
        url: '/firstPackage/pages/reportModule/checkRecordMain/checkRecordMain?id=' + item.id,
      })
    }
  },



  //预览确客码
  previewQrcode(e) {
    let url = e.currentTarget.dataset.url;
    wx.previewImage({
      current: url,
      urls: [url],
    })
  },

  //到底了数据
  scrolltolower() {
    if (this.data.isBottomShow) {
      //已经到底了就不加载了
      return;
    }
    let tempPage = this.data.page + 1;
    this.setData({
      page: tempPage,
      isShowLoading: true,
    })
    this.queryRecordManagerList();
  },
  //下拉刷新
  refreshDownData() {
    console.log("JJLog:下拉刷新来了=====:");
    this.setData({
      scrollRefreshStatus: true,
      page: 0,
      isBottomShow: false,
    })
    this.queryRecordManagerList();
  },


})